package ferus.tigris.lines.Builders;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.graphics.Bitmap;

import ferus.tigris.lines.personages.AbstractBehavior;
import ferus.tigris.lines.personages.EmptyMark;
import ferus.tigris.lines.personages.Mark;
import ferus.tigris.lines.personages.NullMarkBehavior;
import ferus.tigris.lines.personages.ViewsManager;
import ferus.tigris.lines.GameView;
import ferus.tigris.lines.views.Sprite;


public class AbstractBehaviorBuilder {
		
	public AbstractBehavior create(GameView view) {
		Mark behavior = new EmptyMark(view);
		Bitmap img = ImagesPool.instance(view).getEmpty();
		Sprite sprite = new Sprite(img, 200, 1, 1);
		ViewsManager viewManager = new ViewsManager(behavior, sprite); 
		return viewManager;
	}
	
	public AbstractBehavior createRandomMark(GameView view) {
		List<AbstractBehaviorBuilder> builders = new ArrayList<AbstractBehaviorBuilder>();
		builders.add(new CatBuilder());
		builders.add(new BuggyBuilder());
		builders.add(new MouseBuilder());
		builders.add(new BirdBuilder());
		builders.add(new FrogBuilder());
		builders.add(new RabbitBuilder());
		
		Random rnd = new Random();
		AbstractBehaviorBuilder builder = builders.get(rnd.nextInt(builders.size()));
		
		return builder.create(view);
	}

	public AbstractBehavior createNull() {
		AbstractBehavior behavior = new NullMarkBehavior();
		return behavior;
	}

	public AbstractBehavior createByName(GameView gameView, String name) {
		if(name.contains("Rabbit")) {
			AbstractBehaviorBuilder builder = new RabbitBuilder();
			return builder.create(gameView);
		} else
		if(name.contains("Cat")) {
			AbstractBehaviorBuilder builder = new CatBuilder();
			return builder.create(gameView);
		} else
		if(name.contains("Bug")) {
			AbstractBehaviorBuilder builder = new BuggyBuilder();
			return builder.create(gameView);
		} else
		if(name.contains("Mouse")) {
			AbstractBehaviorBuilder builder = new MouseBuilder();
			return builder.create(gameView);
		} else
		if(name.contains("Bird")) {
			AbstractBehaviorBuilder builder = new BirdBuilder();
			return builder.create(gameView);
		} else
		if(name.contains("Frog")) {
			AbstractBehaviorBuilder builder = new FrogBuilder();
			return builder.create(gameView);
		} else 
		if(name.contains("Bear")) {
			AbstractBehaviorBuilder builder = new BearBuilder();
			return builder.create(gameView);
		} else 
		if(name.contains("Pig")) {
			AbstractBehaviorBuilder builder = new PigBuilder();
			return builder.create(gameView);
		} else
		if(name.contains("Null")) {
			return createNull();
		}
		return create(gameView);
	}
	
}